/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from "@mineadmin/form";
import hasAuth from "@/utils/permission/hasAuth.ts";
import { concat } from "lodash-es";
import MaDictSelect from "@/components/ma-dict-picker/ma-dict-select.vue";
import MaRemoteSelect from "@/components/ma-remote-select/index.vue";
import { page as getDevicesList } from "$/attractions/inspection/api/inspectionDevices.ts";

export default function getFormItems(
  formType: "add" | "edit" = "add",
  t: any,
  model: any
): MaFormItem[] {
  return concat([
    {
      label: "巡检计划名称",
      prop: "name",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "巡检计划名称" }) },
      itemProps: { rules: [{ required: true, message: "请输入巡检计划名称" }] },
      labelWidth: '120px',
    },
    {
      label: "巡检周期",
      prop: "cycle",
      render: () => MaDictSelect,
      renderProps: {
        data: [
          { label: "每日", value: 1 },
          { label: "每周", value: 2 },
          { label: "每月", value: 3 },
        ],
        placeholder: "请选择巡检周期",
        clearable: true,
        multiple: false,
      },
      itemProps: { rules: [{ required: true, message: "请选择巡检周期" }] },
    },
    {
      label: "巡检人",
      prop: "person",
      render: "input",
      renderProps: { placeholder: t("form.pleaseInput", { msg: "巡检人" }) },
      itemProps: { rules: [{ required: true, message: "请输入巡检人" }] },
    },
    {
      label: "巡检设备",
      prop: "devices",
      render: () => MaRemoteSelect,
      renderProps: {
        api: getDevicesList,
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((item: any) => ({
              label: item.name || `设备${item.id}`,
              value: item.id,
            }));
          }
          return [];
        },
        placeholder: "请选择巡检设备",
        clearable: true,
        multiple: true,
      },
      itemProps: { rules: [{ required: true, message: "请选择巡检设备" }] },
    },
  ]);
}
